package com.leonzhangxf.springdatastudy;

import com.leonzhangxf.springdatastudy.repo.UserAuditorAwareImpl;
import com.leonzhangxf.springdatastudy.repo.entity.StudentSaveOrUpdateEvent;
import com.leonzhangxf.springdatastudy.repo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.EventListener;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jdbc.repository.config.EnableJdbcAuditing;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author leonzhangxf
 */
@SpringBootApplication
@EnableTransactionManagement
@EnableJdbcAuditing
@Slf4j
public class SpringDataStudyApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringDataStudyApplication.class, args);
    }

    @Bean
    public AuditorAware<User> auditorAware() {
        return new UserAuditorAwareImpl();
    }

    @EventListener(classes = StudentSaveOrUpdateEvent.class)
    public void studentSaveOrUpdateEventListen(StudentSaveOrUpdateEvent event) {
        log.info("Get the student save or update event. {}", event.getMessage());
    }
}
